let Headline = function() {
    this.id = 0;
    this.content = "";
    this.startTime = 0;
    this.endTime = 0;
    this.frequency = 120 * 1000; //默认120s
    this.lastTick = 0;
};

Headline.prototype.isExpired = function (time) {
    return this.lastTick + this.frequency < time;
};

Headline.prototype.toBSON = function() {
    return {
        id : this.id,
        content : this.content,
        startTime : this.startTime,
        endTime : this.endTime,
        frequency : this.frequency
    };
};

Headline.prototype.toJSON = function () {
    return {
        id : this.id,
        content : this.content,
        startTime : this.startTime,
        endTime : this.endTime,
        frequency : this.frequency
    };
};

Headline.prototype.toSimpleJSON = function () {
    return {
        id : this.id,
        content : this.content
    };
};

module.exports.create = function(id, content, startTime, endTime, frequency, lastTick) {
    let headline = new Headline();
    headline.id = id;
    headline.content = content;
    headline.startTime = startTime;
    headline.endTime = endTime;
    headline.frequency = frequency;
    headline.lastTick = lastTick;
    return headline;
};

module.exports.loadFromDocument = function (document) {
    let headline = new Headline();
    headline.id = document["id"];
    headline.content = document["content"];
    headline.startTime = document["startTime"];
    headline.endTime = document["endTime"];
    headline.frequency = document["frequency"];
    headline.lastTick = 0;
    return headline;
};
